package richbar.com.richbar.activity.me.myassets;

import android.view.View;
import android.widget.TextView;
import com.common.base.BaseActivity;
import com.common.util.ToastUtil;
import com.okhttp.network.HttpUtils;
import com.okhttp.network.MyGson;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import richbar.com.richbar.R;
import richbar.com.richbar.bean.RepaidBalanceBean;
import richbar.com.richbar.util.LoadingDialog;
import richbar.com.richbar.util.NetWorkUtil;
import richbar.com.richbar.view.dialog.TipDialog;

/**
 * Created by Administrator on 2018/11/29.
 * 充值余额
 */

public class RepaidBalanceAc extends BaseActivity {
    @BindView(R.id.tv_balance)
    TextView tv_balance;//余额
    @BindView(R.id.tv_rule)
    TextView tv_rule;//使用规则
    private LoadingDialog dialog;

    @Override
    public int initLayout() {
        return R.layout.ac_repaid_balance;
    }

    @Override
    public void initTitle() {

    }

    @Override
    public void initView() {
        ButterKnife.bind(this);
        dialog = new LoadingDialog(RepaidBalanceAc.this, 0);
    }

    @Override
    public void initData() {
        dialog.show();
        NetWorkUtil.getRecharge(new HttpUtils.HttpCallback() {
            @Override
            public void onSuccess(String data) {
                dialog.dismiss();
                final RepaidBalanceBean repaidBalanceBean = MyGson.getInstance().fromJson(data, RepaidBalanceBean.class);
                tv_balance.setText(repaidBalanceBean.getData().getRecharge_balance() + "");
                if (repaidBalanceBean.getData().getRule() != null) {
                    String str = "";
                    for (int i = 0; i < repaidBalanceBean.getData().getRule().size(); i++) {
                        str = str + repaidBalanceBean.getData().getRule().get(i);
                    }
                    tv_rule.setText(str);
                }

                ToastUtil.showToast(RepaidBalanceAc.this, repaidBalanceBean.getMsg());
            }

            @Override
            public void onError(String msg) {
                super.onError(msg);
                dialog.dismiss();
                ToastUtil.showToast(RepaidBalanceAc.this, msg);
            }
        });
    }

    @OnClick({R.id.iv_back, R.id.btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.btn://充值
                TipDialog.showpay(RepaidBalanceAc.this);
                break;

        }
    }
}
